package com.tianruan.dc.modules.sys.user.service.impl;


import com.tianruan.dc.modules.sys.user.entity.db.RolePermissionDO;
import com.tianruan.dc.modules.sys.user.mapper.RolePermissionMapper;
import com.tianruan.dc.modules.sys.user.service.IRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("rolePermissionService")
public class RolePermissionServiceImpl implements IRolePermissionService {

    @Autowired
    private RolePermissionMapper rolePermissionMapper;

    @Transactional
    public void insertRolePermission(String roleId, List<String> permissionIds){
        rolePermissionMapper.deleteByRoleId(roleId);
        permissionIds.stream()
                .map(permissionId->new RolePermissionDO().setRoleId(roleId).setPermissionId(permissionId))
                .forEach(rolePermission->rolePermissionMapper.insert(rolePermission));
    }

}
